 package com.zu.commu.insertDataServlet;

 import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.StringRequestEntity;
 import org.apache.log4j.Logger;
 
 public class PostDataRemote
 {
   private static Logger log = Logger.getLogger(PostDataRemote.class);
 
   public boolean post(String content, String servletURL)
   {
     PostMethod post = new PostMethod(servletURL);
     post.setRequestHeader("Content-type", "text/xml; charset=UTF-8");
     post.setRequestEntity(new StringRequestEntity(content));
 
     HttpClient client = new HttpClient();
 
     post.getParams().setParameter("http.method.retry-handler", 
       new DefaultHttpMethodRetryHandler());
 
     int statusCode = 0;
     boolean flag = true;
     try
     {
       statusCode = client.executeMethod(post);
       if (statusCode != 200) {
         log.error("用Servlet远传数据失败，原因:" + post.getStatusLine());
         flag = false;
       }
     } catch (Exception ex) {
       ex.printStackTrace();
       flag = false;
     } finally {
       post.releaseConnection();
     }
     return flag;
   }
 }
